<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
    <th:block th:include="include :: header('疫情防控信息修改')" />

      <link
      rel="stylesheet"
      href="https://res.wx.qq.com/open/libs/weui/1.1.3/weui.min.css"
    />

    <style type="text/css">
        #imgPreview {
            width: 30%;
            height: 120px;
            margin: 10px auto 0px auto;
            border: 1px solid black;
            text-align: center;
        }
        #prompt3 {
            width: 100%;
            height: 120px;
            text-align: center;
            position: relative;
        }
        #imgSpan {
            position: absolute;
            top: 35px;
            left: 20px;
        }
        .filepath {
            width: 100%;
            height: 100%;
            opacity: 0;
        }
        #img3 {
            height: 100%;
            width: 100%;
            display: none;
        }
        #imgPreview1 {
            width: 30%;
            height: 120px;
            margin: 10px auto 0px auto;
            border: 1px solid black;
            text-align: center;
        }
        #prompt4 {
            width: 100%;
            height: 120px;
            text-align: center;
            position: relative;
        }
        #imgSpan1 {
            position: absolute;
            top: 35px;
            left: 20px;
        }
        #img4 {
            height: 100%;
            width: 100%;
            display: none;
        }
    </style>
</head>
<body class="white-bg">
    <div class="wrapper wrapper-content animated fadeInRight ibox-content">
        <div class="row">
            <div class="col-sm-12">
                <form class="form-horizontal m" id="form-collect-add">
                    <input name="userId" class="form-control" type="hidden">
                    <input name="deptId" class="form-control" type="hidden">
                    <input name="collectType" class="form-control" type="hidden">
                    <input name="userType" class="form-control" type="hidden">
                    <input name="userName" class="form-control" type="hidden">
                    <input name="phonenumber" class="form-control" type="hidden">


                    <div class="form-group">
                        <label class="col-sm-3 control-label"><i class="text-danger">*</i> 安康码状态：</label>
                        <div class="col-sm-8">
                            <div class="radio-box" th:each="dict : ${@dict.getType('akm_status')}">
                                <input type="radio" th:id="${'akmStatus_' + dict.dictCode}" name="akmStatus" th:value="${dict.dictValue}" required="required">
                                <label th:for="${'akmStatus_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label"><i class="text-danger">*</i> 安康码截图：</label>
                        <div class="col-sm-8">
                             <input type="hidden" name="akmPath" th:field="${akmPath}">
                            <!--<div>
                                <input class="form-control" id="akmPath" name="file" type="file">
                            </div>-->
                            <div id="imgPreview">
                                <div id="prompt3">
                                 <span id="imgSpan">
                                 点击上传
                                 <br />
                                 <i class="fa fa-plus"></i>
                                 </span>
                                    <input type="file" id="file" class="filepath" onchange="changepic(this)" accept="image/jpg,image/jpeg,image/png,image/PNG" required="required">
                                    <!--当vaule值改变时执行changepic函数，规定上传的文件只能是图片-->
                                </div>
                                <img src="#" id="img3" onclick="picClick()"/>
                            </div>
                        </div>
                    </div>



                    <div class="form-group">
                        <label class="col-sm-3 control-label"><i class="text-danger">*</i> 核酸检测时间：</label>
                        <div class="col-sm-8">
                            <div class="input-group date">
                            <input type="text" name="hsTime" class="form-control" th:value="${#dates.format(yqInfoCollect.hsTime, 'yyyy-MM-dd HH:mm')}" placeholder="yyyy-MM-dd HH:mm" id="datetime-picker" required="required">
                               <!--  <input name="hsTime" class="form-control" placeholder="yyyy-MM-dd HH:mm:ss" type="text"> -->
                                <span class="input-group-addon"><i class="fa fa-calendar"></i></span>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label"> <i class="text-danger">*</i>  两日内核酸检测结果：</label>
                        <div class="col-sm-8">
                            <div class="radio-box" th:each="dict : ${@dict.getType('hs_result')}">
                                <input type="radio" th:id="${'hsResult_' + dict.dictCode}" name="hsResult" th:value="${dict.dictValue}" th:field="${hsResult}" required="required">
                                <label th:for="${'hsResult_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label"><i class="text-danger">*</i>  行程码14天是否未离肥：</label>
                        <div class="col-sm-8">
                            <div class="radio-box" th:each="dict : ${@dict.getType('sys_yes_no')}">
                                <input type="radio" th:id="${'xcmIsLeave_' + dict.dictCode}" name="xcmIsLeave" th:value="${dict.dictValue}" required="required" th:field="${xcmIsLeave}">
                                <label th:for="${'xcmIsLeave_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label"><i class="text-danger">*</i>  行程码截图：</label>
                        <div class="col-sm-8">

                            <input type="hidden" name="xcmPath" th:field="${xcmPath}">
                            <!--<div>
                                <input class="form-control" id="xcmPath" name="file" type="file">
                            </div>-->
                            <div id="imgPreview1">
                                <div id="prompt4">
                                 <span id="imgSpan1">
                                 点击上传
                                 <br />
                                 <i class="fa fa-plus"></i>
                                 </span>
                                    <input type="file" id="file1" class="filepath" onchange="changepic1(this)" accept="image/jpg,image/jpeg,image/png,image/PNG" required="required">
                                    <!--当vaule值改变时执行changepic函数，规定上传的文件只能是图片-->
                                </div>
                                <img src="#" id="img4" onclick="picClick1()"/>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label"> <i class="text-danger">*</i> 体温是否正常：</label>
                        <div class="col-sm-8">
                            <div class="radio-box" th:each="dict : ${@dict.getType('sys_yes_no')}">
                                <input type="radio" th:id="${'twIsNormal_' + dict.dictCode}" name="twIsNormal" th:value="${dict.dictValue}" th:field="${twIsNormal}" required="required">
                                <label th:for="${'twIsNormal_' + dict.dictCode}" th:text="${dict.dictLabel}"></label>
                            </div>
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-sm-3 control-label">体温异常原因：</label>
                        <div class="col-sm-8">
                           <textarea name="twYcReason" class="form-control">[[${yqInfoCollect.twYcReason}]]</textarea>
                        </div>
                    </div>

                </form>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-sm-12" style="text-align: center">
            <button type="button" class="btn btn-primary" onclick="submitHandler()"><i class="fa fa-check"></i>保 存</button>&nbsp;
        </div>
    </div>
    <th:block th:include="include :: footer" />


  <script src="https://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
  <script src="https://res.wx.qq.com/open/libs/weuijs/1.0.0/weui.min.js"></script>
<script>


var now = new Date();
var year = now.getFullYear(); //年
var month = now.getMonth() + 1; //月
var day = now.getDate(); //日
var hour = now.getHours(); //小时
var order_time = `${year}-${month}-${day} ${hour}:00:00`;

// 日期选择控件
var yearList = [String(year-1),String(year)];
var monthList = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12"];
var dayList = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18",
			"19", "20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "30", "31"
		];
var hourLlist = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "13", "14", "15", "16", "17", "18",
			"19", "20", "21", "22", "23", "24"
		];

var dataList = [];
var index = 0;
    for (var i = 0; i < yearList.length; i++) {
       // if (year <= +yearList[i]) {
            var a = {};
            a.value = yearList[i];
            a.label = `${yearList[i]}年`;
            index++;
            a.children = [];
            for (var j = 0; j < monthList.length; j++) {
                var b = {};
                b.label = `${monthList[j]}月`;
                b.value = monthList[j];
                index++;
                if (year == +yearList[i]) {
                    //if (month - 1 <= j) {
                        a.children[a.children.length] = b;
                    //}
                } else {
                    a.children[a.children.length] = b;
                }
                b.children = [];
                for (var o = 0; o < dayList.length; o++) {
                    var c = {};
                    c.label = `${dayList[o]}日`;
                    c.value = dayList[o];
                    index++;
                    if (month == +monthList[j]) {
                        //if (day - 1 <= o) {
                            b.children[b.children.length] = c;
                       // }
                    } else {
                        b.children[b.children.length] = c;
                    }
                    c.children = [];
                    for (var p = 0; p < hourLlist.length; p++) {
                        var d = {};
                        d.label = `${hourLlist[p]}时`;
                        d.value = hourLlist[p];
                        index++;
                        if (day == +dayList[o]) {
                            //if (hour - 1 <= p) {
                                c.children[c.children.length] = d;
                            //}
                        } else {
                            c.children[c.children.length] = d;
                        }
                    }
                    if (j + 1 == 4 || j + 1 == 6 || j + 1 == 0 || j + 1 == 11) {
                        if (o == 29) o = 31;
                    } else if (j + 1 == 2) {
                        if (
                            (+yearList[i] % 4 == 0 && +yearList[i] % 100 != 0) ||
                            +yearList[i] % 400 == 0
                        ) {
                            if (o == 28) o = 31;
                        } else {
                            if (o == 27) o = 31;
                        }
                    }
                }
            }
            dataList[dataList.length] = a;
       // }
    }
    var appointment = '';
    $('.icon-picker').click(function () {
        $("#datetime-picker").click();
    })

    $("#datetime-picker").click(function () {
    weui.picker(dataList, {
        className: "custom-classname",
        container: "body",
        defaultValue: [year, month, day, hour],
        onChange: function (result) {},
        onConfirm: function (result) {
            appointment = result[0] + "-" + result[1] + "-" + result[2] + " " + result[3] + ":00";
            $("#datetime-picker").val(appointment)
            order_time = `${result[0]}-${result[1]}-${result[2]} ${result[3]}:00:00`
        },
        id: "datetime-picker"
    });
});
</script>
    <script th:inline="javascript">
        var prefix = ctx + "wxcp/epidemic/collect"
          $("#form-collect-add").validate({
            focusCleanup: true
        });

        function submitHandler() {
            if ($.validate.form()) {
                // $.operate.save(prefix + "/add", $('#form-collect-add').serialize());
                var akm = $("#akmPath").val();
                var xcm = $("#xcmPath").val();
                if(akm == '' || akm == null || akm == undefined){
                    $.modal.alertWarning("请先上传安康码");
                    return;
                }
                if(xcm == '' || xcm == null || xcm == undefined){
                    $.modal.alertWarning("请先上传行程码");
                    return;
                }

                var config = {
                    url: prefix + "/edit",
                    type: "post",
                    dataType: "json",
                    data: $('#form-collect-add').serialize(),
                    beforeSend: function () {
                        $.modal.loading("正在处理中，请稍候...");
                        $.modal.disable();
                    },
                    success: function(result) {
                        if (typeof callback == "function") {
                            callback(result);
                        }
                        callback(result);
                    }
                };
                $.ajax(config)
            }
        }

        function callback(result){
            if (result.code == web_status.SUCCESS) {
                // 跳转到保存成功页面
                window.location.href = ctx + "common/success";
            } else if (result.code == web_status.WARNING) {
                $.modal.alertWarning(result.msg)

            }  else {
                $.modal.alertError(result.msg);
            }
        }

        $("input[name='hsTime']").datetimepicker({
            format: "yyyy-mm-dd hh:ii:ss",
            autoclose: true
        });


        //
        function changepic() {
            $("#prompt3").css("display", "none");
            var reads = new FileReader();
            f = document.getElementById('file').files[0];

            //上传图片到后台
            if (f == null) {
                $.modal.alertWarning("请先上传安康码");
                return false;
            }
            var formData = new FormData();
            formData.append('fileName', $("#fileName").val());
            formData.append('file', f);
            $.ajax({
                url: "/common/collect/upload",
                type: 'post',
                cache: false,
                data: formData,
                processData: false,
                contentType: false,
                dataType: "json",
                success: function(result) {
                    console.log(result);
                    console.log(result.filePath);
                    $("#akmPath").val(result.filePath);
                }
            });

            reads.readAsDataURL(f);
            reads.onload = function(e) {
                document.getElementById('img3').src = this.result;
                $("#img3").css("display", "block");
            };
        }

        //
        function changepic1() {
            $("#prompt4").css("display", "none");
            var reads = new FileReader();
            f = document.getElementById('file1').files[0];

            //上传图片到后台
            if (f == null) {
                $.modal.alertWarning("请先上传行程码");
                return false;
            }
            var formData = new FormData();
            formData.append('fileName', $("#fileName").val());
            formData.append('file', f);
            $.ajax({
                url: "/common/collect/upload",
                type: 'post',
                cache: false,
                data: formData,
                processData: false,
                contentType: false,
                dataType: "json",
                success: function(result) {
                    console.log(result);
                    console.log(result.filePath);
                    $("#xcmPath").val(result.filePath);
                }
            });

            reads.readAsDataURL(f);
            reads.onload = function(e) {
                document.getElementById('img4').src = this.result;
                $("#img4").css("display", "block");
            };
        }

        // 点击更换图片
        function picClick(){
            var fileobj = document.getElementById("file");
            fileobj.click();
        }

        // 点击更换图片2
        function picClick1(){
            var fileobj = document.getElementById("file1");
            fileobj.click();
        }
        //加载图片
        $(function () {

            var imgPath3 = [[${yqInfoCollect.akmPath}]];
            var imgPath4 = [[${yqInfoCollect.xcmPath}]];
            $("#img3").attr("src", imgPath3);
            $("#img4").attr("src", imgPath4);
            $("#prompt3").css("display", "none");
            $("#img3").css("display", "block");
            $("#prompt4").css("display", "none");
            $("#img4").css("display", "block");
        })




    </script>
</body>
</html>
